package com.cxm.support.controller;


import com.cxm.support.entity.Chart;
import com.cxm.support.entity.Knowledge;
import com.cxm.support.service.KnowledgeService;
import com.cxm.support.vo.DataVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpSession;
import java.time.LocalDate;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cxm
 * @since 2022-05-22
 */
@Controller
@RequestMapping("/support")
public class KnowledgeController {
    @Autowired
    private KnowledgeService knowledgeService;
    @GetMapping("/knowledgelistdata")
    @ResponseBody
    @RequiresPermissions("知识库管理")
    public DataVO redirect3(Integer page, Integer limit,HttpSession session) {
        String title = (String) session.getAttribute("title");
        String label= (String) session.getAttribute("label");

        return knowledgeService.findData(title,label,page, limit);
    }

    @PostMapping("/knowledgelistadd")
    @ResponseBody
    @RequiresPermissions("知识库管理")
    public String chartlistadd(Knowledge knowledge) {
        LocalDate date = LocalDate.now();
        knowledge.setPublishtime(date);
        knowledgeService.save(knowledge);
        return null;
    }

    //    删除
    @PostMapping("/knowledgelistdelete")
    @ResponseBody

    public String lotteryDelete(Integer id) {

        knowledgeService.removeById(id);
        return null;}

    //搜索
    @PostMapping("/knowledgelist/search")
    @ResponseBody
//    @RequiresPermissions("视频搜索")
    public String search(@RequestParam String title,@RequestParam String label, HttpSession session) {
        System.out.println(title);
        session.setAttribute("title", title);
        session.setAttribute("label", label);


        return null;
    }























}

